<h2 class="title">修改认证电话</h2>

<form method="post" class="edit-mail" id="phone_verify">
    <img src="/resource/www/imgs/renz_phone_1.png" class="img-icon">
    <label class="label fix">
        <span class="text">新手机号码</span>
        <select class="gjselect" name="areacode" id="areacode">
            <{foreach from=$data item=v}>
                <option value="<{$v.areaCode}>" <{if $v.areaCode == '86'}>selected<{/if}>><{$v.country}>(+<{$v.areaCode}>)</option>
            <{/foreach}>
        </select>
        <span class="line"></span>
        <input type="text" name="num" id="num" placeholder="电话号码" class="number" value="">
    </label>

    <label class="label fix">
        <span class="text">验证码</span>
        <input type="text" id="code" name="code" class="yanz-code" value="">
        <input type="button" onclick="getCode(this)" name="" id="" value="获取验证码" class="huoq-code">
    </label>

    <input type="button" class="submit" onclick="verifyCode()"  value="确定">
    <input type="hidden" name="uid" value="<{$uid}>">
</form>

<!-- <div class="succ-mail">
    <img src="/resource/www/imgs/renz_phone_2.png" class="img">
    <p class="prompt">您的电话已修改成功，当前认证电话为 </p>
    <p class="mail-text">中国(＋86)  13564871249</p>
</div> -->

 <script>

    function getCode(current){
        var areacode = $("#areacode").val();
        var num = $.trim($("#num").val());

        if (!num) {
            layer.msg("电话号码不能为空");
            return false;
        }

        var phoneNum="+"+areacode+num;
        $.post('/guider/valid_phone',{num:num,phoneNum:phoneNum},function(o){
      	  if(o.status==0){
      		var url = "/guider/send_msg/"+o.phoneNum;
            var i = 60;
            var timer = null;
            timer = setInterval(function() {
                i--;
                if (i < 10) {
                    i = '0' + i;
                }
                $(current).val('剩余' + i + 's');
                $(current).attr('disabled', true);
                if (i <= 0) {
                    clearInterval(timer);
                    $(current).val('再次获取');
                    $(current).attr('disabled', false);
                    i = 60;
                }
            }, 1000);

            $.ajax({
                type : "get",
                url : url,
                success : function(response) {
                    res = JSON.parse(response);
                    if(res.status == 0){
                       layer.msg("验证码发送成功");
                    }else{
                        layer.msg("验证码发送失败，稍后再试");
                    }
                }
            });
      	  }else{
      		  layer.msg("该电话已被使用，请重新输入");
      	  }
          },'json');
    }

    function verifyCode(){
        var areacode = $("#areacode").val();
        var num = $("#num").val();

        var phoneNum=areacode+num;
        var code = $("#code").val();

        if (!$.trim(num)) {
            layer.msg("电话号码不能为空");
            return false;
        }

        if(!$.trim(code)){
            layer.msg("短信验证码不能为空");
            return false;
        }
        var url = "/guider/verify?code="+code+"&num="+phoneNum;
        $.ajax({
            type : "get",
            url : url,
            success : function(response) {
                res = JSON.parse(response);
                if(res.status == 0){
                    $('#phone_verify').submit();
                }else{
                    layer.msg("短信验证码不正确");
                }
            }
        });
    }

</script>
<script>
    $('.show_phone_credit').addClass("mactive");
    $('.credit_nav').addClass("active");
    $('.down-menu').eq(0).show();
</script>
